package com.starview.star.compiler.ast;

import com.starview.platform.data.EvaluationException;
import com.starview.platform.data.IFunction;
import com.starview.platform.data.IValue;
import com.starview.platform.data.type.IType;
import com.starview.platform.data.type.StandardTypes;
import com.starview.platform.data.type.TypeUtils;
import com.starview.platform.data.value.Factory;
import com.starview.star.compiler.Display;
import com.starview.star.compiler.util.PrettyPrintDisplay;
import com.starview.star.operators.CafeEnter;

public class MacroDisplay implements IFunction
{
  public static final String name = "__macro_display";

  @CafeEnter
  public static IValue enter(ASyntax term) throws EvaluationException
  {
    PrettyPrintDisplay disp = new PrettyPrintDisplay();
    Display.display(disp, term);
    return Factory.newString(disp.toString());
  }

  @Override
  public IValue enter(IValue... args) throws EvaluationException
  {
    return enter((ASyntax) args[0]);
  }

  @Override
  public IType getType()
  {
    return type();
  }

  public static IType type()
  {
    return TypeUtils.functionType(ASyntax.type, StandardTypes.stringType);
  }
}
